package com.ruoyi.generator.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.generator.entity.Equipment;
import com.ruoyi.generator.entity.Region;
import com.ruoyi.generator.entity.Task;
import com.ruoyi.generator.po.Device;
import com.ruoyi.generator.service.ManagementService;
import com.ruoyi.generator.service.SiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.yaml.snakeyaml.events.Event;

import java.util.ArrayList;
import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/management")
public class ManagementController extends BaseController {

    @Autowired
    private ManagementService managementService;

    @GetMapping("region/list")
    public TableDataInfo regionList(Region region) {
        startPage();
        List<Region> list = managementService.selectRegionList(region);
        return getDataTable(list);
    }

    /**
     * 区域新增按钮  暂时无用
     * @param region
     * @return
     */
    @PostMapping("/region/addRegion")
    public AjaxResult addRegion(@RequestBody Region region) {
        int result = managementService.addRegion(region);
        return AjaxResult.success(result);
    }

    @PostMapping("/region/updateRegion")
    public AjaxResult updateRegion(@RequestBody Region region) {
        int result = managementService.updateRegion(region);
        return AjaxResult.success(result);
    }

    @GetMapping("equipment/list")
    public TableDataInfo equipmentList(Equipment equipment) {
        //startPage();
        List<Equipment> list = managementService.selectEquipmentList(equipment);
        return getDataTable(list);
    }

    /**
     * 新增设备信息
     *
     * @param equipment
     * @return
     */
    @PostMapping("/equipment/addEquipment")
    public AjaxResult addEquipment(@RequestBody Equipment equipment) {
        int result = managementService.addEditRegion(equipment);
        return AjaxResult.success(result);
    }

    @PostMapping("/equipment/updateEquipment")
    public AjaxResult updateEquipment(@RequestBody Equipment equipment) {
        int result = managementService.updateEquipment(equipment);
        return AjaxResult.success(result);
    }

    @GetMapping("task/list")
    public TableDataInfo TaskList(Task task) {
//        startPage();
        List<Task> list = managementService.selectTaskList(task);
        return getDataTable(list);
    }

    @PostMapping("/task/addTask")
    public AjaxResult addTask(@RequestBody Task task) {
        int result = managementService.addEditTask(task);
        return AjaxResult.success(result);
    }

    @PostMapping("/task/updateTask")
    public AjaxResult updateTask(@RequestBody Task task) {
        int result = managementService.updateTask(task);
        return AjaxResult.success(result);
    }

    /**
     * 查询区域列表
     *
     * @return
     */
    @GetMapping("region/regionList")
    public AjaxResult getRegionList() {
        List<Region> regionList = managementService.getRegionList();
        return AjaxResult.success(regionList);
    }

    /**
     * 根据区域ID获取设备信息
     *
     * @param id
     * @return
     */
    @GetMapping("equipment/getEquipmentListByAreaId")
    public TableDataInfo getEquipmentListByAreaId(@RequestParam Integer id) {
        startPage();
        Equipment equipment = new Equipment();
        equipment.setAreaId(String.valueOf(id));
        List<Equipment> list = managementService.getEquipmentList(equipment);
        return getDataTable(list);
    }

    /**
     * 根据设备ID获取任务信息
     *
     * @param id
     * @return
     */
    @GetMapping("task/taskList")
    public TableDataInfo getTaskList(@RequestParam Integer id) {
        startPage();
        Task task = new Task();
        task.setEquipmentId(String.valueOf(id));
        List<Task> taskList = managementService.getTaskList(task);
        return getDataTable(taskList);
    }

    /**
     * 根据区域、设备、任务ID查询信息
     */
//    @GetMapping("/plan/info")
//    public AjaxResult getPlanInfo(){
//
//    }



}
